import { defineStore } from 'pinia'
// import { useGeneralStore } from './general'
import { http } from '~/composables/http';
import { login, getUserInfo } from '~/composables/user'


export const useUserStore = defineStore('user', () => {
  const id = ref('')
  const name = ref('')
  const bio = ref('')
  const image = ref('')

  const loginFun = async (username,password) => {
    const params = {
      username,
      password
    }
    return await login(params)
  }
  const getUserInfoList = async (id) => {
    return await getUserInfo()
  }

  return {
    id,
    name,
    bio,
    image,
    loginFun,
    getUserInfoList
  }
},{
  persist: process.client && {
    storage: sessionStorage
  }
})
// export const useUserStore = defineStore('user', {
//   state: () => ({ 
//     id: '',
//     name: '',
//     bio: '',
//     image: ''
//   }),
//   actions: {
//     async login(username,password) {
//       const obj = {
//           method: "POST",
//           url: '/api/login',
//           body: {
//             username,
//             password
//           }
//       }
//       return await http(obj)
//     }
//   },
//   persist: true
// })